/**
 * 

 */
package edu.vt.ece.rt.quorum.util;

import java.io.Serializable;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import edu.vt.ece.rt.dstm.QObject;

/**
 * To Save the List of object read and write by Transaction
 * @author Sudhanshu
 *
 */
public class CreateDeleteSet implements Serializable {
	Set<QObject> createList;
	Set<QObject> deleteList;
	
	public CreateDeleteSet(){
		createList = Collections.synchronizedSet(new HashSet<QObject>());
		deleteList = Collections.synchronizedSet(new HashSet<QObject>());
	}
	
	public void addCreateObject(QObject obj){
		synchronized (createList) {
			createList.add(obj);
		}
	}
	
	public void addDeleteObject(QObject obj){
		synchronized (deleteList) {
			deleteList.add(obj);
		}
	}
	
	public Set<QObject> getCreateObjects(){
		synchronized (createList) {
			return createList;
		}
	}
	
	public Set<QObject> getDeleteObjects(){
		synchronized (deleteList) {
			return deleteList;
		}
	}

	/**
	 * Removes all the entries
	 */
	public void Clear() {
		createList = Collections.synchronizedSet(new HashSet<QObject>());
		deleteList = Collections.synchronizedSet(new HashSet<QObject>());		
	}
}
